<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
  </head>
  <body>
    <div id="app">
      <p>
        <router-link to="/foo">Foo</router-link>
        <router-link to="/bar">Bar</router-link>
      </p>
      <router-view></router-view>
    </div>
  </body>
  <script>
    const Foo = {
      template: `
        <div>foo页面</div>
      `,
    };

    const Bar = {
      template: `
        <div>
          <div>bar页面</div>
          <router-link to="/">首页</router-link>
        </div>
      `,
    };
    const routes = [
      { path: "/foo", component: Foo },
      { path: "/bar", component: Bar },
    ];
    window.onload = () => {
      const router = new VueRouter({
        routes, // (缩写) 相当于 routes: routes
      });
      const app = new Vue({
        router,
      }).$mount("#app");
    };
  </script>
</html>
